package 查找;

public class basicLookup {
    public static void main(String[] args) {
        //基本查找的实现

        //基本查找的思路：
        //通过遍历数组内的元素一个个对比，虽然容易，但是效率不高
        //有序和无序都可以用

        //数组
        int[] arr = {1,3,2,5,4};
        int number = 2;
        int index = basiclookup(arr , number);
        System.out.println(index);

        int[] arr1 = {131, 127, 147, 81, 103, 23, 7, 79};
        int number1 = 7;
        int index1 = basiclookup(arr1 , number1);
        System.out.println(index1);

    }

    private static int basiclookup(int[] arr , int number) {
        //如果找到了就返回对应的索引，没找到则返回-1
        for (int i = 0; i < arr.length; i++) {
            if (arr[i] == number) {
                return i;
            }
        }
        return -1;
    }
}
